import 'package:flutter/material.dart';
import 'package:flutter_base_library/index.dart';
import 'package:get/get.dart';
import 'alarm_picture_list_controller.dart';

class AlarmPictureListPage extends StatelessWidget {
  final controller = Get.find<AlarmPictureListController>();
  AlarmPictureListPage({super.key});
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("记录列表"),
      ),
      body: Container(
        width: Get.width,
        color: const Color(0xFFF5F5F5),
        child: _bodyContent(),
      ),
    );
  }

  Widget _bodyContent() {
    return ListView.separated(
      padding: const EdgeInsets.fromLTRB(0, 20, 0, 20),
      itemBuilder: (_, index) {
        return GestureDetector(
          onTap: () {
            controller.itemClicked(index);
          },
          behavior: HitTestBehavior.translucent,
          child: _itemContent(index),
        );
      },
      separatorBuilder: (_, index) {
        return const SizedBox(height: 10);
      },
      itemCount: controller.imgList.length,
    );
  }

  Widget _itemContent(index) {
    var pic = controller.imgList[index];
    String url = AppData.instance.baseUrl! + (pic.tpdz ?? "");
    int? milliseSecond = pic.cjsj?.toInt();
    String timeString = "创建时间：";
    if (milliseSecond != null) {
      DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(
        milliseSecond * 1000,
      );
      timeString = "$timeString${toLocalDateTimeByDateTime(dateTime)}";
    }
    return Container(
      margin: const EdgeInsets.fromLTRB(15, 0, 15, 0),
      padding: const EdgeInsets.fromLTRB(15, 10, 15, 10),
      height: 95,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(15),
      ),
      child: Row(
        children: [
          Image.network(
            url,
            fit: BoxFit.fill,
            width: 60,
            height: 60,
          ),
          const SizedBox(width: 15),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  "巡检类型：${pic.xjlx}",
                  style: const TextStyle(
                    color: Color(0xFF101010),
                    fontSize: 14,
                  ),
                ),
                Row(
                  children: [
                    Expanded(
                      child: Text(
                        timeString,
                        textAlign: TextAlign.right,
                        style: const TextStyle(
                          color: Color(0xFF999999),
                          fontSize: 12,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
